package com.dmagic.cms.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;

import com.dmagic.cms.common.dao.CommonDao;
import com.dmagic.cms.common.exception.ServiceException;
import com.dmagic.cms.common.util.NumberUtil;
import com.dmagic.cms.common.util.StringUtil;
import com.dmagic.cms.entity.UploadFileInfo;

@Component
public class UploadFileInfoDao extends CommonDao<UploadFileInfo, Long> {

	public List<UploadFileInfo> getUploadFileInfoListByUploadFileSetInfoId(Long uploadFileSetInfoId) {
		return this.findBy("uploadFileSetInfoId", uploadFileSetInfoId);
	}

	public Integer getUploadFileInfoCountByUploadFileSetInfoId(Long uploadFileSetInfoId) {
		Criteria criteria = this.getSession().createCriteria(UploadFileInfo.class);
		criteria.add(Restrictions.eq("uploadFileSetInfoId", uploadFileSetInfoId));
		Long resultsLong = (Long) criteria.setProjection(Projections.rowCount()).uniqueResult();
		Integer results = NumberUtil.toInteger(resultsLong);
		return results;
	}

	public List<UploadFileInfo> getUploadFileInfoListIncludeDeleteInfoByUploadFileInfoIds(
			Long[] uploadFilenfoIds) {
		String sql = "select * from dmagic_upload_file_info where uploadFileInfoId in (:uploadFileInfoIds)";
		Map<String, Object> m = new HashMap<String, Object>();
		m.put("uploadFileInfoIds", uploadFilenfoIds);
		return query(sql, m, UploadFileInfo.class);
	}
}
